package com.violorch.game;

import android.content.Context;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.TextView;

/**
 * Created by violorch on 4/23/15.
 */
public class Card extends FrameLayout {

    private int number = 0;
    private TextView label;

    public Card(Context context) {
        super(context);

        label = new TextView(getContext());
        label.setTextSize(32);
        label.setBackgroundColor(0x33ffffff);
        label.setTextColor(0xff000000);
        LayoutParams lp = new LayoutParams(-1, -1);
        lp.setMargins(10, 10, 0, 0);
        addView(label, lp);
        setNumber(0);

    }

    public boolean equals(Card o) {
        return getNumber() == o.getNumber();
    }

    public int getNumber() {
        return number;
    }

    public void setNumber(int number) {
        this.number = number;
        if (number <= 0 )
            label.setText("");
        else
            label.setText("" + number);
        label.setGravity(Gravity.CENTER);
        if (number == 0) {
            label.setBackgroundColor(0x33ffffff);
        } else if (number == 2) {
            label.setBackgroundColor(0xffEDE4DB);
            label.setTextColor(0xff766E66);
        } else if (number == 4) {
            label.setBackgroundColor(0xffECDFC9);
            label.setTextColor(0xff766E66);
        } else if (number == 8) {
            label.setBackgroundColor(0xffEBB37F);
        } else if (number == 16) {
            label.setBackgroundColor(0xffEA9B6C);
        } else if (number == 32) {
            label.setBackgroundColor(0xffE98668);
        } else if (number == 64) {
            label.setBackgroundColor(0xffE76E4B);
        } else if (number == 128) {
            label.setBackgroundColor(0xffEBCD79);
            label.setTextColor(0xff766E66);
        } else if (number == 256) {
            label.setBackgroundColor(0xffEAC96A);
            label.setTextColor(0xff766E66);
        } else if (number == 512) {
            label.setBackgroundColor(0xffEAC65B);
            label.setTextColor(0xff766E66);
        } else if (number == 1024) {
            label.setBackgroundColor(0xffDC462F);
        } else if (number >= 2048) {
            label.setBackgroundColor(0xffED462F);
        }

    }

}
